package zhang.dd.controooer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerExecutionChain;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

import javax.servlet.http.HttpServletRequest;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

@RestController
public class hello {


    @zhang(value = "333")
    private String sname;

    @GetMapping("/name")
    public String sname(HttpServletRequest request) throws Exception {





        return "hahaha......好神奇 -----";
    }

    public static void values(Object obj,String snamee) throws NoSuchFieldException, IllegalAccessException {

        Class<?> a = obj.getClass();
        Field sname = a.getDeclaredField(snamee);
        boolean annotationPresent = sname.isAnnotationPresent(zhang.class);
        if (annotationPresent){
            zhang annotation = sname.getAnnotation(zhang.class);
            String value = annotation.value();
            sname.set(obj,value);
        }

    }

    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
        hello h=new hello();
        Class<? extends hello> a = h.getClass();

        values(h,"sname");

        System.out.println(h.sname);

    }
}
